<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
<!DOCTYPE html>
<html lang="zh-cn" style="height: 100%">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no">
    <title><?=VIEW_TITLE?></title>
    <link href="<?php echo base_url('/assets/bs/'); ?>css/bootstrap.min.css" rel="stylesheet">
    <link href="<?php echo base_url('/assets/css/'); ?>my_common.css" rel="stylesheet">
    <script src="http://cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="http://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
</head>
<body>
<?php
$this->load->view('admin_header.php');
?>
<div class="container-fluid">
    <div id="main_div" style="position:relative;max-width: 800px;margin: 0 auto 10px auto;">
        <div style="max-width: 720px;overflow-x: hidden;margin: 0 auto 10px auto;">
            <input type="text" class="form-control" placeholder="请输入文章标题" id="title"
                   value="<?php echo $original_article['title']; ?>">
            <input style="margin-top: 5px;" type="text" class="form-control" placeholder="请输入原文链接(非必填项)" id="url"
                   value="<?php echo $original_article['url']; ?>">
        </div>
        <div style="max-width: 720px;overflow-x: hidden;margin: 0 auto 10px auto;">
            <script id="container" name="content" type="text/plain">
            </script>
        </div>
    </div>
    <div class="hidden-xs" id="btn_group" style="position:fixed;top: 200px;">
        <!--        <div>-->
        <!--            <button type="button" class="btn btn-default btn-sm">-->
        <!--                <span class="glyphicon glyphicon-floppy-disk"></span> 保存-->
        <!--            </button>-->
        <!--        </div>-->
        <div style="margin-top: 10px;">
            <button type="button" class="btn btn-default btn-sm" onclick="doSave()">
                <span class="glyphicon glyphicon-open"></span> 保存
            </button>
        </div>
    </div>
    <div class="visible-xs-block">
    		<div style="margin-top: 10px;margin-bottom: 10px;text-align: right;">
            <button type="button" class="btn btn-default btn-sm" onclick="doSave()">
                <span class="glyphicon glyphicon-open"></span> 保存
            </button>
        </div>
    </div>
</div>
<!--<button type="button" class="btn btn-default" onclick="a()">Default</button>-->
<?php
$this->load->view('mfooter.php');
?>
<script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
<script src="<?php echo base_url('/assets/bs/'); ?>js/bootstrap.min.js"></script>
<script type="text/javascript" src="<?php echo base_url('/assets/ueditor/ueditor.config.js?v=').time(); ?>"></script>
<script type="text/javascript" src="<?php echo base_url('/assets/ueditor/'); ?>ueditor.all.js"></script>
<script type="text/javascript">
    var w_width = document.documentElement.clientWidth;
    var w_height = document.documentElement.clientHeight;
    var right = (w_width - 720) / 2 - 80;
    console.log(right);
    if (right <= 0) {
        right = 10;
    }
    $('#btn_group').css('right', right);
    //    $('#main_div').height(main_div_height + 'px');

    var ue = UE.getEditor('container', {
//        autoHeightEnabled: true,
//        autoFloatEnabled: true,
//        saveInterval:1000
        initialFrameHeight: w_height - 270,
        enableAutoSave: false, //禁止自动保存
        autoSyncData: false,//自动同步编辑器要提交的数据
    });
    ue.ready(function () {
        ue.setContent('<?php echo str_replace(array("'"),"\'",str_replace(array("\r\n","\r","\n"),"", $original_article["article_html"])) ?>');
//        ue.execCommand('drafts');
    });
    function doSave() {
        var html = ue.getContent();
        var text = ue.getContentTxt();
        var title = $('#title').val();
        var url = $('#url').val();
        if (title == '') {
            alert('标题不能留空!');
            return false;
        }
        if (html == '' || text == '') {
            alert('内容不能留空!');
            return false;
        }
        $.ajax({
            url: '<?php echo site_url('/taskworker/save')?>',
            type: 'post',
            dataType: 'json',
            data: {
                html: html,
                text: text,
                title: title,
                url: url,
                manager_id:<?php echo $manager_id;?>
            },
            success: function (data) {
                if (data == 'success') {
                    alert('修改成功');
                    window.location.href = "<?php echo site_url('/taskworker/userCenter')?>";
                }
            }
        });
    }
</script>
</body>
</html>
